At present, complex software is designed with a separate component for each function. In this case, each component is designed to provide a common function to be used for various programs.
When such software is written in an object-oriented language as typified by JAVA, a high-level, object-oriented programming language developed by Sun Microsystems, each function is classified into class, object, and method to be provided. When a function is desired to be used, a program generates an object to invoke a method.
When such object-oriented software is designed, not all the calculation may be needed. For example, an object including two pieces of information is used for giving and receiving values, when only one piece of the information may actually be used, depending on where the program is located. In such a case, calculation for the information of no use would be performed in vain; the existence of such a useless performance may sometimes affect the performance of software significantly.
An approach called dead code elimination (DCE) (also called “dead store elimination”) is well-known as an optimization technology for a program with a compiler. This is an optimization technology to eliminate a code, of which a calculation result is determined not to be used, by analyzing a method and the like within a compiling target. The codes include an unreachable code on a control flow, resolved conditionals, and a code defining a value not to be used (dead store). As a specific approach, backward dataflow optimization that analyses a reaching use of a definition value is performed in combination with forward dataflow optimization such as constant propagation and copy propagation on CFG (Control Flow Graph) or SSA form (Static Single Assignment Form).
However, while the above-described program optimization technology with DCE is effective in that it eliminates a waste of a complex equation such as mathematical calculation, it is defective in that it is not easy to function with an object-oriented language, which is divided into components, such as JAVA, a high-level, object-oriented programming language developed by Sun Microsystems. The primary two reasons for that will be shown as follows:
One of the reasons is that a target of DCE elimination is limited to a code within a method. Generally, for an object-oriented language such as JAVA, a high-level, object-oriented programming language developed by Sun Microsystems, a plurality of multilevel method invocations are performed to generate a piece of information. When such a multilevel method invocation is performed, it is not subject to the DCE elimination.
The other reason is that a value written on a heap can be globally referenced, and DCE cannot analyze a reaching use for such a global value. Generally, an object of JAVA, a high-level, object-oriented programming language developed by Sun Microsystems, is generated on a heap. As such, DCE cannot analyze a reaching use and a code cannot be eliminated.
FIG. 7 is a diagram showing an example of a method invocation of a program with an object-oriented language.
A part of a program shown in FIG. 7 represents the case in which an object reference v is defined (v's def), and its use is an invocation of a method mtd1 for making an object v its receiver. In this example, a method mtd1 invokes a method mtd2 by substituting a value of 1 into an instance variable i1 of an object v, then a method mtd2 substitutes a value of 2 into an instance variable i2 of an object v.
In this case, even if a substituted result of a value into an instance variable of an object v is not used in the other places, this result is not eliminated by DCE because the object v is used for invoking a method mtd1.
Both substituted results of values into instance variables i1 and i2 of object v shown in FIG. 7 are not used. In other words, both of them are dead store and this substitution is useless.
However, even if an object is not actually used, the above-described calculation of no use cannot be eliminated only by a single optimization with DCE, because the calculation appears to be used for a method invocation and the writing into the object is treated globally.